<?php
/* @var $this InvoiceController */
/* @var $model Invoice */
/* @var $customer Customer */
/* @var $address Address */
/* @var $form CActiveForm */
?>

<?php
$this->breadcrumbs=array(
	'Rechnungen'=>array('invoice/admin'),
	'Neue Rechnung'=>array('invoice/newInvoice'),
	'Waren hinzufügen',
);

setlocale(LC_ALL, "de_DE.UTF-8");
?>

<h2>Waren hinzufügen</h2>


<?php
$invoice_status = ModelHelper::modelToArray(Status::model()->findAll());
?>

<div id="image">
	<img src="<?php echo Yii::app()->request->baseUrl.'/images/logo.gif';?>" width="100" height="100" alt="Weineinblicke Logo">

	<p>
		A-6800 Feldkirch<br>
		Grenzweg 9<br>
		Tel. 0043 (0)664/1937383<br>
		Fax 0043 (0)5522/77545/15<br>
		vonbun.josef@inode.at<br>
		www.weineinblicke.at<br><br>
		<b>
		ATU 62370927<br>
		GEB-Nr: 466697<br>
		MwSt. Nr: 266.750<br>
		</b>
		<br>
		Feldkirch, am<?php echo(" " . $model->date); ?><br><br>
		Lieferung am<?php echo(" " . $model->date); ?><br><br>
	</p>
</div>


<br><br><br>
<h4 id="no_margin"><?php echo($customer->first_name . " " . $customer->last_name); ?></h4>

<?php echo($address->address); ?>

<br>

<?php echo($address->postcode . " " . $address->place); ?>

<br>

<?php echo($address->country); ?>

<div class="clear"></div>

<h3 id="no_margin">Rechnungs-Nr: <?php echo(" " . $model->invoice_id); ?> </h3> <br>
Ihre Kundennummer: <?php echo($customer->customer_id); ?> <br><br><br>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'model-form',
	'enableAjaxValidation'=>false,
/* 	'stateful'=>true, */
)); ?>

	<?php echo $form->errorSummary($model); ?>
<!--
	<div class="row">
		<?php //echo $form->labelEx($model,'status'); ?>
		<?php //echo $form->dropDownList($model,'status', array_combine($invoice_status, $invoice_status)); ?>
		<?php //echo $form->error($model,'status'); ?>
	</div>
-->
<?php

	$criteria = new CDbCriteria;

	$conditions=array();
	$conditions[0] = 'customer_id=:customer_id';
	$conditions[1]= 'invoice_id=:invoice_id';
	$criteria->condition = implode(' AND ', $conditions);

	$criteria->params = array(':customer_id'=>$model->customer_id, ':invoice_id'=>$model->invoice_id);

	$purchases = Purchase::model()->findAll($criteria);
 
    $purchases_array = new CArrayDataProvider($purchases, array(
       'keyField' => 'purchase_id', 
    ));
?>

	<?php $this->widget('zii.widgets.grid.CGridView', array(
		'cssFile' => Yii::app()->getRequest()->getBaseUrl() . '/css/tableStyle_align_left.css',
		'id'=>'customer-grid',
		'template' => '{items}{pager}',
		'dataProvider'=>$purchases_array,
		'columns'=>array(
	        array (
	            'class'=>'CButtonColumn',
	            'template'=>'{delete}',
	            'buttons'=>array(
	            	'delete'=>array(
	            		'imageUrl'=>Yii::app()->request->baseUrl.'/images/delete.png',
	            	),
	            ),
	        ),
			array(
				'name'=>'Bezeichnung',
	            'value'=>'$data->wine->product_information',
				'htmlOptions'=>array('class'=>'align_left'),
			),
			array(
				'name'=>'Einheit',
	            'value'=>'Yii::app()->format->formatNumber($data->wine->bottle_size)',
			),
			array(
	            'name'=>'%',
	            'value'=>'Yii::app()->format->formatNumber($data->wine->alcohol_concentration)',
	        ),	
	        array(
	            'name'=>'Sorte',
	            'value'=>'$data->wine->type',
	        ),	
	        array(
	            'name'=>'Preis in €',
	            'value'=>'Yii::app()->format->formatNumber($data->wine->sale_price_net)',
	        ),	
	        array(
	            'name'=>'Menge',
	            'value'=>'$data->amount',
	        ),
	        array(
	            'name'=>'Gesamt in €',
	            'value'=>'Yii::app()->format->formatNumber($data->wine->sale_price_net * $data->amount)',
	        ),		

		),
	)); ?>	
	
	<br>
	
	<?php echo CHtml::button('Waren hinzufügen', array('submit' => array('invoice/addPurchase', 'invoice_id'=>$model->invoice_id, 'customer_id'=>$model->customer_id))); ?>

	
<?php $this->endWidget(); ?>

</div><!-- form -->


<div id="summary_table">
	<table border="1">
	  <tr>
	    <th>Nettobetrag</th>
	    <th>€</th>
	    <th><?php echo(Yii::app()->format->formatNumber($this->getSumForInvoice($model->invoice_id)));?></th>
	  </tr>
	  <tr>
	    <td>20% Mehrwertsteuer</td>
	    <td>€</td>
	    <td>0,00</td>
	  </tr>
	  <tr>
	    <td>10% Mehrwertsteuer</td>
	    <td>€</td>
	    <td>0,00</td>
	  </tr>
	  
	  <tr class="sum">
	    <td><b>Bruttobetrag</b></td>
	    <td><b>€</b></td>
	    <td><b><?php echo(Yii::app()->format->formatNumber($this->getSumForInvoice($model->invoice_id)));?></b></td>
	  </tr>
	</table>
</div>

<div class="clear"></div>

<br><br>
<h4>Herzlichen Dank für Ihre Bestellung! </h4>
Bis zur vollständigen Bezahlung bleibt die Ware unser Eigentum!
<br><br>

<?php echo CHtml::button('Speichern'); ?>



